package JUC.第02章_Future;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;

public class D7_CompletableFuture的结果合并 {
    public static void main(String[] args) {

        CompletableFuture<Integer> cf1 =
                CompletableFuture.supplyAsync(() -> {
                    int result = ThreadLocalRandom.current().nextInt(10);//随机获取[0-9]
                    return result;
                });
        CompletableFuture<Integer> cf2 =
                CompletableFuture.supplyAsync(() -> {
                    int result = ThreadLocalRandom.current().nextInt(10);//随机获取[0-9]
                    return result;
                });
        CompletableFuture<String> cfh = cf1.thenCombine(cf2, (x, y) -> {
            return "cf1值为:" + x + "\ncf2值为:" + y + "\n两个值得和为:" + (x + y);
        });//结果合并
        System.out.println(cfh.join());


    }
}
